{% extends 'inc/layout.twig' %}

{% if pg_name is not defined %}
{% set pg_name=entity.id ? '编辑用户' : '添加用户' %}
{% endif %}

{% block content %}
    <div class="container">
        {% if reset_pwd is not defined %}
        <div class="row">
            <a href="/user" class="btn btn-default btn-sm">
                <i class="fa fa-share"></i> 用户列表</a>
        </div>
        {% endif %}

        <div class="row">
            <div class="wrap-monitor">

                        <form action="" method="post" class="form form-horizontal">
                            <input type="hidden" name="id" value="{{ entity.id }}">

                            <div class="form-group">
                                <label class="control-label col-md-1 col-sm-1">用户名</label>
                                <div class="col-md-4 col-sm-4">
                                    <input type="text" name="username" value="{{ entity.username }}" maxlength="20" class="form-control">
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="control-label col-md-1 col-sm-1">密码</label>
                                <div class="col-md-4 col-sm-4">
                                    <input type="password" name="password" value="" maxlength="20" class="form-control">
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="control-label col-md-1 col-sm-1">重复密码</label>
                                <div class="col-md-4 col-sm-4">
                                    <input type="password" name="repeat_pwd" value="" maxlength="20" class="form-control">
                                </div>
                            </div>

                            {% if reset_pwd is not defined %}
                              <div class="form-group">
                                <label class="control-label col-md-1 col-sm-1">用户组</label>
                                <div class="col-md-2 col-sm-2">
                                    <select class="form-control" name="group_id">
                                        {% if entity.id is not empty %}
                                            {% set gid=entity.group_id %}

                                            {% for grp in group_list%}
                                                {% if grp['gid']==gid %}
                                                <option value="{{ grp['gid'] }}" selected="selected">{{ grp['label_zh'] }}</option>
                                                {% else %}
                                                <option value="{{ grp['gid'] }}">{{ grp['label_zh'] }}</option>
                                                {% endif %}
                                            {% endfor %}

                                        {% else %}

                                            {% for grp in group_list %}
                                                {% if grp['label']=='guest' %}
                                                <option value="{{ grp['gid'] }}" selected="selected">{{ grp['label_zh'] }}</option>
                                                {% else %}
                                                <option value="{{ grp['gid'] }}">{{ grp['label_zh'] }}</option>
                                                {% endif %}
                                            {% endfor %}

                                        {% endif %}
                                    </select>
                                </div>
                            </div>
                            {% endif %}

                            <div class="form-group">
                                <div class="col-md-10 col-md-offset-1">
                                    <button class="btn btn-info" id="btn-reg-user">
                                    <i class="fa fa-check"></i> 创建</button>
                                </div>
                            </div>
                        </form>
                    </div>
        </div>

{% endblock %}

{% block plus_js %}
    <script>
        require(['user']);
    </script>
{% endblock %}